package com.hehao.java_basic.lambda;

import java.util.function.*;

/**
 * @Author Damon
 * @Date 2024/5/6 16:02
 */
public class JdkFunctionDemo {
    public static void main(String[] args) {
        //supplier没有输入 只有一个输出
        Supplier<String> supplier = ()->"this is a supplier demo";
        System.out.println(supplier.get());

        //consumer只有一个输入  没有输出
        Consumer<String> consumer = i-> System.out.println("this is a consumer demo" + i);
        consumer.accept(" ++=consumer demo");

        //Function 输入T  输出R
        Function<Integer,String> function = i -> "this is a function demo" + i;
        System.out.println(function.apply(1));

        //UnaryOperator 输入输出都是T
        UnaryOperator<Integer> unaryOperator = i -> i * i;
        System.out.println(unaryOperator.apply(5));

        //BiFunction 输入T U 输出R
        BiFunction<Integer,Integer,String> biFunction = (i,j) -> i +"*"+j+"="+i*j;
        System.out.println(biFunction.apply(8, 9));
    }
}
